package main;


import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class TAdapter extends KeyAdapter implements Runnable, Commons, MouseListener, MouseMotionListener {

	public InputHandler inputHandler;
	public int MouseX, MouseY;
	public Thread input;
	public TAdapter(){
		inputHandler = new InputHandler();
		input = new Thread(this);
		input.start();
		
	}
	@Override
	public void run() {
		
	}
	

	public void keyReleased(KeyEvent e) {
		int key = e.getKeyCode();		
		if(key == KeyEvent.VK_F2){				
			inputHandler.F2_RELEASE = true;
			inputHandler.F2_PUSH = false;	
		}
		if (key == KeyEvent.VK_SHIFT) {				
			inputHandler.SHIFT_RELEASE = true;
			inputHandler.SHIFT_PUSH = false;
		}
		if (key == KeyEvent.VK_SPACE) {
			inputHandler.SPACE_RELEASE = true;
			inputHandler.SPACE_PUSH = false;
		}
		if (key == KeyEvent.VK_UP) {
			inputHandler.UP_RELEASE = true;
			inputHandler.UP_PUSH = false;
		}
		if (key == KeyEvent.VK_DOWN) {
			inputHandler.DOWN_RELEASE = true;
			inputHandler.DOWN_PUSH = false;	
		}	
		if (key == KeyEvent.VK_LEFT) {
			inputHandler.LEFT_RELEASE = true;
			inputHandler.LEFT_PUSH = false;	
		}	
		if (key == KeyEvent.VK_RIGHT) {
			inputHandler.RIGHT_RELEASE = true;
			inputHandler.RIGHT_PUSH = false;
		}
		if (key == KeyEvent.VK_W) {
			inputHandler.W_RELEASE = true;
			inputHandler.W_PUSH = false;
		}
		if (key == KeyEvent.VK_A) {
			inputHandler.A_RELEASE = true;
			inputHandler.A_PUSH = false;	
		}	
		if (key == KeyEvent.VK_S) {
			inputHandler.S_RELEASE = true;
			inputHandler.S_PUSH = false;	
		}	
		if (key == KeyEvent.VK_D) {
			inputHandler.D_RELEASE = true;
			inputHandler.D_PUSH = false;
		}
			
		
	}

	@SuppressWarnings("unchecked")
	public void keyPressed(KeyEvent e) {
		
			int key = e.getKeyCode();		
			if(key == KeyEvent.VK_F2){				
				inputHandler.F2_PUSH = true;
				inputHandler.F2_RELEASE = false;
			}
			if (key == KeyEvent.VK_SHIFT) {				
				inputHandler.SHIFT_PUSH = true;
				inputHandler.SHIFT_RELEASE = false;
			}
			if (key == KeyEvent.VK_SPACE) {
				inputHandler.SPACE_PUSH = true;
				inputHandler.SPACE_RELEASE = false;
			}
			if (key == KeyEvent.VK_UP) {
				inputHandler.UP_PUSH = true;
				inputHandler.UP_RELEASE = false;	
			}
			if (key == KeyEvent.VK_DOWN) {
				inputHandler.DOWN_PUSH = true;
				inputHandler.DOWN_RELEASE = false;
			}	
			if (key == KeyEvent.VK_LEFT) {
				inputHandler.LEFT_PUSH = true;
				inputHandler.LEFT_RELEASE = false;	
			}	
			if (key == KeyEvent.VK_RIGHT) {
				inputHandler.RIGHT_PUSH = true;
				inputHandler.RIGHT_RELEASE = false;
			}	
			if (key == KeyEvent.VK_W) {
				inputHandler.W_RELEASE = false;
				inputHandler.W_PUSH = true;
			}
			if (key == KeyEvent.VK_A) {
				inputHandler.A_RELEASE = false;
				inputHandler.A_PUSH = true;	
			}	
			if (key == KeyEvent.VK_S) {
				inputHandler.S_RELEASE = false;
				inputHandler.S_PUSH = true;	
			}	
			if (key == KeyEvent.VK_D) {
				inputHandler.D_RELEASE = false;
				inputHandler.D_PUSH = true;
			}

	}
	
	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		inputHandler.MOUSE_PRESSED = true;
		MouseX = e.getX();
		MouseY = e.getY();
		if(e.getButton() == MouseEvent.BUTTON1) {
			inputHandler.MOUSE_LEFT_CLICK = true;
		}
		else if(e.getButton() == MouseEvent.BUTTON3) {
			inputHandler.MOUSE_RIGHT_CLICK = true;
		}
	}
	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		inputHandler.MOUSE_MOVED = true;
		MouseX = e.getX();
		MouseY = e.getY();
	}
}
